<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of WriteOff
 *
 * @author Administrator
 */
class Lock extends WMS_Controller
{


    function __construct()
    {
        parent::__construct();
        $this->load->service('/wms/inventory_on_order_service');
        $this->load->model('/Common_model');
        header("Content-type: text/html; charset=utf-8");
    }
    function lock($id)
    {
       $id=intval(trim($id));
       if($id>38147){
           js_goto(getenv("HTTP_REFERER"), "no data");exit;
       }
        //#配件
        $partsList = $this->Common_model->selectCustom('mt_product_parts', array('pid' => $id));
        $productFirst = $this->Common_model->selectFirst('mt_product', array('id' => $id));
        $orderFirst = $this->Common_model->selectFirst('mt_order', array('id' => $productFirst['oid']));


        $ok = FALSE;
        if ($partsList && $productFirst && $orderFirst)
        {
            $where = array(
                'order_id' => $productFirst['order_num'] . '-' . $productFirst['id'],
            );
            $is_set = $this->inventory_on_order_service->get_on_track($where);
            if (is_array($is_set) && count($is_set) < 1)
            {
                $ok = true;
            }
            else
            {
                js_goto(getenv("HTTP_REFERER"), "It has been locked!Please do not repeat");exit;
            }
        }
        else
        {
            js_goto(getenv("HTTP_REFERER"), "no data");exit;
        }
        if ($ok === FALSE)
        {
            return FALSE;
        }

        //订单锁定WMS可用库存
//                $setOk = $this->inventory_on_order_service->set_onorder_parts_list_t($partsList,$orderFirst['merchant_num'],$productFirst['inWarranty']);
        $wms_lock_url = blang_url('wmsApi/Stock/lock');
        $user = 'tomrepair.es';
        $timestamp = time();
        $pass = 'omstomrepaires20161214';
        $sign = md5($user . $timestamp . $pass);
        $data['user'] = $user;
        $data['timestamp'] = $timestamp;
        $data['sign'] = $sign;
        $data['data']['parts_list'] = $partsList;
        $data['data']['product_first'] = $productFirst;
//           echo http_build_query($data);
        $result = CurlPost($wms_lock_url, $data);
        if ($result)
        {
            js_goto(getenv("HTTP_REFERER"), "Success locked");
        }
        else
        {
            js_goto(getenv("HTTP_REFERER"), "Failed Lock ");
        }
    }
    function lock_panel()
    {
        $this->load->view('defaults/wms/lock_for_old_panel');
        $this->load->view('defaults/common/footer');
    }
}

?>
